<template>
  <section :class="['login-page', { 'sign-up-mode': signUpMode }]">
    <div class="login-box">
      <div class="inner-box">
        <div class="forms">
          <!-- 登录表单 -->
          <ad-form class="sign-in-form" @submit.prevent="login">
            <template #header>
              <ad-logo />
              <ad-login-title title="欢迎回来" ask="尚未注册?" toggle="注册" @toggleMode="toggleMode" />
            </template>
            <template #content>
              <ad-input label="用户名" v-model="form.username" />
              <ad-input label="密码" v-model="form.password" type="password" />
              <input type="submit" value="登录" class="sign-btn" />
              <ad-login-title ask="忘记密码?" toggle="找回密码" />
            </template>
          </ad-form>
          <!-- 注册 表单-->
          <ad-form class="sign-up-form" @submit.prevent="login">
            <template #header>
              <ad-logo />
              <ad-login-title title="开始使用" ask="已经拥有了一个账户?" toggle="登录" @toggleMode="toggleMode"></ad-login-title>
            </template>
            <template #content>
              <ad-input label="用户名" v-model="form.username"></ad-input>
              <ad-input label="邮箱" v-model="form.email" type="email"></ad-input>
              <ad-input label="密码" v-model="form.password" type="password"></ad-input>
              <input type="submit" value="注册" class="sign-btn" />
              <p class="text">
                注册前,请确认同意
                <a href="#">服务条款</a>
                和
                <a href="#">隐私政策</a>
              </p>
            </template>
          </ad-form>
        </div>
        <!-- 右侧轮播区域 -->
        <ad-carousel />
      </div>
    </div>
  </section>
</template>
<script lang="ts" setup>
import http from "@utils/http"
const router = useRouter()
const form = ref({
  /** 用户名 */
  username: "",
  /** 密码 */
  password: "",
  // 邮箱
  email: ""
})
/** 显示登录表单 */
const signUpMode = ref(false)
/** 切换登录/注册 */
const toggleMode = () => {
  signUpMode.value = !signUpMode.value
}
const login = async (e: Event) => {
  const { data: res } = await http.post("login", form.value)
  ElMessage.warning("Test")
  if (res.meta.status == 200) {
    ElMessage.success("登陆成功")
    sessionStorage.setItem("token", res.data.token)
    router.push("home")
  }
}
</script>
<style lang="scss">
.login-page {
  width: 100%;
  min-height: 100vh;
  overflow: hidden;
  background-color: #1a1a1a;
  padding: 2rem;
  @include flex;
  justify-content: center;
  .login-box {
    position: relative;
    width: 100%;
    max-width: 1020px;
    height: 640px;
    background-color: #fff;
    border-radius: 3.3rem;
    box-shadow: 0 15px 60px -30px rgba(251, 251, 251, 0.896);
    .inner-box {
      position: absolute;
      width: calc(100% - 4.1rem);
      height: calc(100% - 4.1rem);
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      .forms {
        position: absolute;
        height: 100%;
        width: 45%;
        top: 0;
        left: 0;
        display: grid;
        grid-template-columns: 1fr;
        grid-template-rows: 1fr;
        transition: 0.8s ease-in-out;
        .sign-btn {
          display: inline-block;
          width: 100%;
          height: 43px;
          background-color: #151111;
          color: #fff;
          border: none;
          cursor: pointer;
          border-radius: 0.8rem;
          font-size: 0.8rem;
          margin-bottom: 2rem;
          transition: 0.3s;
          &:hover {
            background-color: #8371fd;
          }
        }
        .text {
          color: #bbb;
          transition: 0.3s;
          font-size: 0.7rem;
          a:hover {
            color: #8371fd;
          }
        }
        .sign-up-form {
          opacity: 0;
          pointer-events: none;
        }
      }
    }
  }
}

.sign-up-mode {
  .login-box {
    .inner-box {
      .forms {
        left: 55%;
        .sign-in-form {
          opacity: 0;
          pointer-events: none;
        }
        .sign-up-form {
          opacity: 1;
          pointer-events: all;
        }
      }
      .ad-carousel {
        left: 0%;
      }
    }
  }
}

@media (max-width: 850px) {
  .login-page {
    padding: 1.5rem;
    .login-box {
      height: auto;
      max-width: 550px;
      overflow: hidden;
      .inner-box {
        position: static;
        transform: none;
        width: revert;
        height: revert;
        padding: 2rem;
        .forms {
          position: revert;
          width: 100%;
          height: auto;
          .ad-form {
            .ad-login-title {
              margin: 1rem 0;
            }
          }
          .sign-up-form {
            transform: translateX(100%);
          }
        }
      }
    }
  }
  .sign-up-mode {
    .login-box {
      .inner-box {
        .forms {
          .sign-in-form {
            transform: translateX(-100%);
          }
          .sign-up-form {
            transform: translateX(0%);
          }
        }
      }
    }
  }
}

@media (max-width: 530px) {
  .login-page {
    padding: 1rem;

    .login-box {
      border-radius: 2rem;

      .inner-box {
        padding: 1rem;
        .forms {
          form {
            padding: 1rem 2rem 1.5rem;
          }
        }
      }
    }
  }
}
</style>
